package dp.mobile.sbm;

import java.util.ArrayList;

import android.app.ActivityGroup;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

public class HomeGroup extends ActivityGroup {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View view = getLocalActivityManager().startActivity(HomeActivity.TAG, 
				new Intent(this,HomeActivity.class)  
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))  
                .getDecorView();
		sGroup = this;
		mHistory = new ArrayList<View>();
		
		replaceView(view);
	}
	
	public void replaceView(View v) {
		mHistory.add(v);
		setContentView(v);
	}
	
	public void back() {  
		if(mHistory.size() > 0) {  
			mHistory.remove(mHistory.size() - 1);  
			setContentView(mHistory.get(mHistory.size() - 1));  
		} else {  
			finish();  
		}  
    }  
  
   @Override  
    public void onBackPressed() {  
	   sGroup.back();  
	   return;  
    }  
	
	public static HomeGroup getGroup() {
		return sGroup;
	}
	
	private ArrayList<View> mHistory;
	private static HomeGroup sGroup;
}
